package com.cn.jinl.controller;


import com.cn.jinl.api.IOnDutyWeekService;
import com.cn.jinl.domain.OnDutyWeek;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/ondutyweek")
public class OnDutyWeekController {

    @Autowired
    private IOnDutyWeekService onDutyWeekService;

    @RequestMapping("/getOnDutyWeekList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<OnDutyWeek>> getOnDutyWeekList(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<OnDutyWeek>> response = new JsonResponse<>();
        List<OnDutyWeek> onDutyWeeks = onDutyWeekService.getOnDutyWeekList();
        response.setResult(onDutyWeeks);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/addOnDutyWeek/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addOnDutyWeek(OnDutyWeek onDutyWeek, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyWeekService.addOnDutyWeek(onDutyWeek);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteOnDutyWeek/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteOnDutyWeek(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyWeekService.deleteOnDutyWeek(id);
        return CommonUtil.getResponseData(response,result);
    }

    //新部署的环境需要执行
    @RequestMapping("/api/addOnDutyWeek")
    @ResponseBody
    public JsonResponse<String> addApiOnDutyWeek(OnDutyWeek onDutyWeek) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = onDutyWeekService.addOnDutyWeek(onDutyWeek);
        return CommonUtil.getResponseData(response,result);
    }

}
